package com.bianguo.android.iocdemo.view.widget.state;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.view.animation.OvershootInterpolator;

public class MerginState extends SplashState {

    public MerginState(float mCircleR, float mRotateRadius, int animTime) {
        ValueAnimator animator = ValueAnimator.ofFloat(mCircleR, mRotateRadius);
        animator.setDuration(animTime);
        animator.setInterpolator(new OvershootInterpolator());
        animator.addUpdateListener(valueAnimator -> {
            if (stateListener != null) {
                stateListener.updateCurrentRotateRadius((float) valueAnimator.getAnimatedValue());
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                if (stateListener != null) {
                    stateListener.onAnimEnd(MerginState.this);
                }
            }
        });
        animator.reverse();
    }

    @Override
    public void drawState(Canvas canvas) {
        if (stateListener != null) {
            stateListener.onDrawState(this, canvas);
        }
    }
}
